{% extends 'django_ledger/layouts/content_layout_1.html' %}
{% load i18n %}
{% load static %}
{% load django_ledger %}

{% block view_content %}
    <div class="container">
        <div class="columns is-multiline">
            <div class="column is-12">
                {% include 'django_ledger/vendor/includes/card_vendor.html' with vendor=bill_model.vendor %}
            </div>
            <div class="column is-12">
                {% include 'django_ledger/bills/includes/card_bill.html' with bill=bill_model style='bill-detail' entity_slug=view.kwargs.entity_slug %}
                <form action="{% url 'django_ledger:bill-update' entity_slug=view.kwargs.entity_slug bill_pk=bill_model.uuid %}"
                      method="post">
                    {% csrf_token %}
                    {{ form }}
                    <button type="submit"
                            class="button is-primary is-fullwidth djetler_my_1">{% trans 'Save Bill' %}</button>

                    <a href="{% url 'django_ledger:bill-detail' entity_slug=view.kwargs.entity_slug bill_pk=bill_model.uuid %}"
                       class="button is-small is-dark is-fullwidth mt-2">{% trans 'Back to Bill Detail' %}</a>
                    <a href="{% url 'django_ledger:bill-list' entity_slug=view.kwargs.entity_slug %}"
                       class="button is-small is-info is-fullwidth mt-2">{% trans 'Bill List' %}</a>
                    <a href="{% url 'django_ledger:entity-dashboard' entity_slug=view.kwargs.entity_slug %}"
                       class="button is-small is-info is-outlined is-fullwidth mt-2">{% trans 'Go To Dashboard' %}</a>

                </form>
            </div>
            <div class="column is-12">
                {% bill_item_formset_table itemtxs_formset %}
            </div>

            {% if bill_model.is_configured %}
                <div class="column is-12">
                    <div class="card">
                        <div class="card-header">
                            <p class="card-header-title">{% trans 'Bill State' %}</p>
                        </div>
                        <div class="card-body">
                            <div class="card-content">
                                <div class="columns is-multiline">
                                    <div class="column is-12">
                                        <h3 class="is-size-3">{% trans 'Bill State' %}</h3>
                                        <p>{{ bill_model.cash_account }}:
                                            {% currency_symbol %}{{ bill_model.get_amount_cash | currency_format }}</p>
                                        <p>{{ bill_model.prepaid_account }}:
                                            {% currency_symbol %}{{ bill_model.get_amount_prepaid | currency_format }}</p>
                                        <p>{{ bill_model.unearned_account }}:
                                            {% currency_symbol %}{{ bill_model.get_amount_unearned | currency_format }}</p>
                                    </div>
                                    <div class="column is-12">
                                        <h3 class="is-size-3">{% trans 'Ledger State' %}</h3>
                                        <p>{{ bill_model.cash_account }}:
                                            {% currency_symbol %}{{ bill_model.amount_paid | currency_format }}</p>
                                        <p>{{ bill_model.prepaid_account }}:
                                            {% currency_symbol %}{{ bill_model.amount_receivable | currency_format }}</p>
                                        <p>{{ bill_model.unearned_account }}:
                                            {% currency_symbol %}{{ bill_model.amount_unearned | currency_format }}</p>
                                    </div>
                                    {% now "Y" as current_year %}
                                    {% now "m" as current_month %}
                                    <div class="column is-6">
                                        <a class="button is-outlined is-small is-primary is-fullwidth"
                                           href="{% url 'django_ledger:ledger-bs-month' ledger_pk=bill_model.ledger.uuid entity_slug=view.kwargs.entity_slug year=current_year month=current_month %}">
                                            {% trans 'Balance Sheet' %}</a>
                                    </div>
                                    <div class="column is-6">
                                        <a class="button is-outlined is-small is-info is-fullwidth"
                                           href="{% url 'django_ledger:ledger-ic-month' ledger_pk=bill_model.ledger.uuid entity_slug=view.kwargs.entity_slug year=current_year month=current_month %}">
                                            {% trans 'Income Statement' %}</a>
                                    </div>
                                    <div class="column is-12">
                                        <a class="button is-small is-warning is-fullwidth"
                                           href="{% url 'django_ledger:ledger-update' ledger_pk=bill_model.ledger.uuid entity_slug=view.kwargs.entity_slug %}">
                                            {% trans 'Bill Ledger' %}
                                        </a>
                                        <a class="button is-small is-info is-fullwidth mt-2"
                                           href="{% url 'django_ledger:je-list' ledger_pk=bill_model.ledger.uuid entity_slug=view.kwargs.entity_slug %}">
                                            {% trans 'Ledger Journal Entries' %}
                                        </a>
                                        <a href="{% url "django_ledger:bill-action-lock-ledger" entity_slug=view.kwargs.entity_slug bill_pk=bill_model.uuid %}"
                                           class="button is-small is-success is-fullwidth mt-2">{% trans 'Lock Ledger' %}</a>
                                        <a href="{% url "django_ledger:bill-action-unlock-ledger" entity_slug=view.kwargs.entity_slug bill_pk=bill_model.uuid %}"
                                           class="button is-small is-danger is-fullwidth mt-2">{% trans 'Unlock Ledger' %}</a>
                                        <a href="{% url "django_ledger:bill-action-force-migrate" entity_slug=view.kwargs.entity_slug bill_pk=bill_model.uuid %}"
                                           class="button is-small is-danger is-fullwidth mt-2">{% trans 'Force Migrate' %}</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="column is-12">
                    <div class="card animate__animated animate__tada">
                        <div class="card-header">
                            <p class="card-header-title">{% trans 'Bill Configuration' %}</p>
                        </div>
                        <div class="card-body">
                            <div class="card-content">
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.cash_account.id_for_label }}" class="label">
                                            {{ form.cash_account.label }}</label>
                                        {{ form.cash_account }}
                                    </div>
                                </div>
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.prepaid_account.id_for_label }}" class="label">
                                            {{ form.prepaid_account.label }}</label>
                                        {{ form.prepaid_account }}
                                    </div>
                                </div>
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.unearned_account.id_for_label }}" class="label">
                                            {{ form.unearned_account.label }}</label>
                                        {{ form.unearned_account }}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% endif %}

        </div>
    </div>
{% endblock %}
